package com.hycc.single;

import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j2;
import java.lang.reflect.Constructor;

/*
* 枚举是单例的
* */
public enum EnumSingle {

    INSTANCE;

    public EnumSingle getInstance(){
        return INSTANCE;
    }
}

@Log4j2
class EnumTest{
    @SneakyThrows
    public static void main(String[] args) {
        EnumSingle instance1 = EnumSingle.INSTANCE;
        Constructor<EnumSingle> declaredConstructor = EnumSingle.class.getDeclaredConstructor(String.class,int.class);
        declaredConstructor.setAccessible(true);
        EnumSingle instance2 = declaredConstructor.newInstance();

        //NoSuchMethodException
        log.info(instance1);
        log.info(instance2);
    }
}